package com.hsck.order.kds.base.isnoam.view

import android.content.Context
import android.graphics.Canvas
import android.graphics.DashPathEffect
import android.graphics.Paint
import android.graphics.PathEffect
import android.util.AttributeSet
import android.view.View

/**
 * @author isnoam
 * @package_name DottedLineView
 * @date 2024-09-29
 * @description：垂直分割线
 */
class VerticalDottedLineView : View {
    private var paint: Paint? = null

    constructor(context: Context?) : super(context) {
        init()
    }

    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
        init()
    }

    constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(
        context,
        attrs,
        defStyle
    ) {
        init()
    }

    private fun init() {
        paint = Paint()
        paint!!.setColor(-0x272723) // 设置颜色为 #D8D8DD
        paint!!.style = Paint.Style.STROKE
        paint!!.strokeWidth = 2f // 设置线条宽度

        // 设置虚线效果：10px 的线段 + 5f 的间隔
        val intervals = floatArrayOf(10f, 5f)
        val effect: PathEffect = DashPathEffect(intervals, 0f)
        paint!!.setPathEffect(effect)
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        // 绘制垂直虚线
        canvas.drawLine(
            (width / 2).toFloat(), 0f, (width / 2).toFloat(), height.toFloat(),
            paint!!
        )
    }
}


